package com.rjkj.medicalwaste.utils

import android.util.Log
import com.rjkj.medicalwaste.bean.Decoder03Bean
import com.rjkj.medicalwaste.bean.Decoder04Bean
import com.rjkj.medicalwaste.bluetooth.BluetoothSPP

object BlueDeviceHelper {
    const val BALANCERESULTCODE = "81" //出秤，入秤，置零。返回Code码
    const val PRINTRESULTCODE = "03" //打印，返回Code码
    const val REALRESULTCODE = "04" //实时信息，返回Code码

    private const val TAG = "BlueDeviceHelper"
    fun sendHanMessage(btSPP: BluetoothSPP, message: ByteArray){
        Log.e(TAG, "sendHanMessage: $message", )
        btSPP.send(message, false)
    }
    fun sendRealTimeDataMessage(btSPP: BluetoothSPP, message: String){
        btSPP.send(SerializeUtil.hexStringToByteArray(message), false)
    }
    fun sendPrintDataMessage(btSPP: BluetoothSPP, message: String){
        btSPP.send(SerializeUtil.hexStringToByteArray(message), false)
    }
    fun readDecoder04Message(string: String): Decoder04Bean {
       return Decoder.decoder04(string)
    }
    fun readDecoder03Message(string: String): Decoder03Bean {
        return Decoder.decoder03(string)
    }
    fun checkDecoderStr03(str: String?): Boolean {
//        // TODO: 2021/5/8 长度的判断不严谨
        return true
//        if (str != null && str.length >= 10) {
//            val cmd = str.substring(6, 8)
//            return cmd == "01"
//        }
//        return false
    }

    fun checkDecoderStr04(str: String?): Boolean {
        // TODO: 2021/5/8 长度的判断不严谨
        if (str != null && str.length >= 10) {
            val cmd = str.substring(4, 6)
            return cmd == REALRESULTCODE
        }
        return false
    }

    fun checkDecoderStr81(str: String?): Boolean {
        return false
    }
}